
#include <pic.h>
#include "my_macros.h"
volatile near bit TimeI_10ms;

near bit Time_10ms;
near bit Time_100ms;
bit Time_500ms;
near bit Time_1000ms;
near bit Time_5000ms;


void SysClock_Init ( void )
{
	CLRWDT();
	TMR0 = 0;
	OPTION_REG = 0;
	OPTION_REG = 0x06;					  /* TMR 1:256 */
	T0IF = 0;
	T0IE = 1;
}

void SysTime( void )
{
	static bank1 unsigned char Divider_500ms = 50, Divider_5Sec = 5, Divider_1Sec = 2, Divider_100ms = 10;

	Time_10ms = FALSE;
	Time_100ms = FALSE;
	Time_500ms = FALSE;
	Time_1000ms = FALSE;
	Time_5000ms = FALSE;

	if ( TimeI_10ms )
	{
		TimeI_10ms = 0;
		Time_10ms = TRUE;

		if ( --Divider_100ms == 0 )
		{
			Divider_100ms = 10;
			Time_100ms = TRUE;
		}

		if ( --Divider_500ms == 0 )
		{
			Divider_500ms = 50;
			Time_500ms = TRUE;
			if ( --Divider_1Sec == 0 )
			{
				Divider_1Sec = 2;
				Time_1000ms = TRUE;
				if ( --Divider_5Sec == 0 )
				{
					Divider_5Sec = 5;
					Time_5000ms = TRUE;
				}
			}
		}
	}
} 
